<?php
class App_Module_Admin_Component_Articles_Tpl_List extends App_Module_Admin_Tpl_List
{
	protected $_showCells = array('date', 'title', 'icons');
	protected $_emptyListMessage = 'NO_ARTICLES';

    public function GetList($ctrlName, $blog, $filter, $page, $themeId)
    {
        $onPage = Mozg_Cfg::Get('admin/articles')->GetPerPage();

        $paginator = new Mozg_Paginator($page, $onPage);
        $pattern = Mozg::Router('http')->Create('module=admin&ctrl=' .$ctrlName. '&action=list&blog=' .$blog->GetId(). '&page=__page__');

        $this->ctrlName = $ctrlName;
        $this->blog = $blog;

        if ($themeId)
        {
	        $this->mainThemeEntry = Mozg_Mapper::Get('Articles')->GetOne(array('id' => $themeId, 'blogId' => $blog->GetId()));

	        if ($this->mainThemeEntry)
	        {
	        	array_unshift($this->_showCells, 'drag');
	        	Mozg::SubAction()->Set('Right Sidebar', array($this->GetTpl('ThemeList'), 'GetList'), array($ctrlName, $blog, $this->mainThemeEntry));
	        }
        }

        $icons = array(
        	array(
        	'add' => array(
        					'title' => 'ADD',
        					'url' => Mozg::Router('http')->Create('module=admin&ctrl=' .$ctrlName. '&action=add&blog=' .$blog->GetId())
        					),
        	)
        );

        $objects = Mozg_Mapper::Get('Articles')->GetList($filter, $paginator);
        $paginator->SetTotalCount(Mozg_Mapper::Get('Articles')->GetTotalRows());
        $content = $this->CreateList($objects, $paginator, $pattern);

        return $this->GetTpl('Base')->LoadTemplate($this->blog->GetTitle(), $content, $icons);
    }

	protected function GetCellDrag($obj)
	{
		return $this->GetTpl('Icon')->GetIcon('drag', '#', Mozg_Lang::_('DRAG'), array('data-id' => $obj->GetId(), 'data-title' => $obj->GetTitle()));
	}

	protected function GetCellDate($obj)
	{
		return Mozg::Lib('date')->Format($obj->GetPublishDate());
	}

	protected function GetCellTitle($obj)
	{
		$this->obj = $obj;
		return $this->render('articles/list/_title.phtml');
	}

	protected function GetCellIcons($obj)
	{
        $icons = array(
        	'comments' => array(
        					'title' => 'комментарии' .$obj->GetCommentsNum(),
        					'url' => Mozg::Router('http')->Create('module=admin&ctrl=' .$this->ctrlName. '&action=commentslist&blog=' .$this->blog->GetId(). '&id=' .$obj->GetId())
        					),

        	'articles' => array(
        					'title' => 'режим выбора статей по теме',
        					'url' => Mozg::Router('http')->Create('module=admin&ctrl=' .$this->ctrlName. '&action=list&blog=' .$this->blog->GetId(). '&main_theme_id=' .$obj->GetId())
        					),

        	'edit' => array(
        					'title' => 'EDIT',
        					'url' => Mozg::Router('http')->Create('module=admin&ctrl=' .$this->ctrlName. '&action=add&blog=' .$this->blog->GetId(). '&id=' .$obj->GetId())
        					),

        	'delete' => array(
        					'title' => 'DELETE_ARTICLE?',
        					'url' => Mozg::Router('http')->Create('module=admin&ctrl=' .$this->ctrlName. '&action=del&blog=' .$this->blog->GetId(). '&id=' .$obj->GetId())
        					),

        );
		return $this->GetTpl('Icon')->GetIconSet($icons, 'list');
	}
}